import time

from selenium import webdriver
from selenium.webdriver.common import alert
from selenium.webdriver.common.by import By
from selenium.webdriver.support.expected_conditions import alert_is_present
from selenium.webdriver.support.wait import WebDriverWait

from PO.BasePage.pageAction import BasePage

class SearchPage(BasePage):
    def __init__(self, driver, url):
        super().__init__(driver, url)
    #进入小红书
    def go_to_xhs(self):
        self.get()
    #登陆
    def login(self,username):
        time.sleep(5)
        self.input(locator=(By.XPATH,'//*[@placeholder = "输入手机号"]'),text=username)
        time.sleep(5)
        self.click(locator=(By.XPATH,'//*[@id="app"]/div[1]/div/div[1]/div[3]/div[2]/form/label[2]/span'))
        time.sleep(5)
        self.click(locator=(By.XPATH,'//*[@id="app"]/div[1]/div/div[1]/div[3]/div[3]/span/div'))
        time.sleep(10)
        self.click(locator=(By.XPATH,'//*[@id="app"]/div[1]/div/div[1]/div[3]/div[2]/form/button'))
        time.sleep(5)
    #搜索
    def search(self,text):
        time.sleep(10)
        self.click(locator=(By.XPATH,'//*[@id="search-input"]'))
        time.sleep(5)
        self.input(locator=(By.XPATH,'//*[@id="search-input"]'),text=text)
        time.sleep(5)
        self.click(locator=(By.XPATH,'//*[@id="global"]/div[1]/header/div[1]/div/div[2]'))
        time.sleep(5)
        self.screenshot(name_prefix="screenshot")
        self.click(locator=(By.XPATH,'//*[@id="global"]/div[1]/header/div[1]/div/div[1]'))
        time.sleep(5)
    #发布视频
    def launch_video(self):
        time.sleep(10)
        self.click(locator=(By.XPATH,'//*[@id="global"]/div[2]/div[1]/ul/div[1]/li[2]/a/span'))
        time.sleep(10)
        self.switch_to_window()
        time.sleep(10)
        self.click(locator=(By.XPATH,'//*[@id="web"]/div/div/div/div[2]/div[1]/div/input'))
        self.switch_to_window()
        #上传视频/照片设置等
        time.sleep(10)
        self.click(locator=(By.XPATH,'//*[@id="publish-container"]/div[2]/div[1]/div[1]/div[4]/div/div/div/div[1]/div/input'))
        time.sleep(3)
        self.input(locator=(By.XPATH,'//*[@id="publish-container"]/div[2]/div[1]/div[1]/div[4]/div/div/div/div[1]/div/input'),text='啦啦啦啦')
        time.sleep(3)
        self.click(locator=(By.XPATH,'//*[@id="quillEditor"]/div'))
        self.input(locator=(By.XPATH,'//*[@id="quillEditor"]/div'),text='11111')
        time.sleep(3)
        self.click(locator=(By.XPATH,'//*[@id="topicBtn"]'))
        time.sleep(3)
        self.click(locator=(By.XPATH,'//*[@id="quill-mention-item-1"]/div/span[1]'))
        time.sleep(3)
        self.click(locator=(By.XPATH,'//*[@id="publish-container"]/div[2]/div[1]/div[1]/div[6]/div/div[2]/div/form/div/div[2]/div/div/div/div/div[2]/span/svg'))
        time.sleep(3)
        self.click(locator=(By.XPATH,'/html/body/div[11]/div/div/div/div/div[1]/div/div[2]'))
        time.sleep(3)
        self.click(locator=(By.XPATH,'//*[@id="publish-container"]/div[2]/div[2]/div/button[1]/div'))
        time.sleep(3)
        #上传图文
    def launch_picture(self):
        time.sleep(5)
        self.click(locator=(By.XPATH, '//*[@id="global"]/div[2]/div[1]/ul/div[1]/li[2]/a/span'))
        time.sleep(5)
        self.switch_to_window()
        #验证登陆
        time.sleep(15)
        #新窗口
        self.switch_to_window()
        self.click(locator=(By.XPATH, '//*[@id="web"]/div/div/div/div[1]/div[2]/span'))
        self.click(locator=(By.XPATH,'//*[@id="web"]/div/div/div/div[2]/div[1]/div/input'))
        time.sleep(10)
        self.click(locator=(By.XPATH,'//*[@id="web"]/div/div/div/div/div[1]/div[1]/div[4]/div/div/div/div[1]/div/input'))
        self.input(locator=(By.XPATH,'//*[@id="web"]/div/div/div/div/div[1]/div[1]/div[4]/div/div/div/div[1]/div/input'),text='2222')
        time.sleep(3)
        self.click(locator=(By.XPATH,'//*[@id="web"]/div/div/div/div/div[2]/div/button[1]/div'))

    #发布评论
    def comment(self):
        time.sleep(10)
        self.click(locator=(By.XPATH,'//*[@id="exploreFeeds"]/section[1]/div/div'))
        time.sleep(5)
        self.click(locator=(By.XPATH,'//*[@id="noteContainer"]/div[4]/div[3]/div/div/div[1]/div[1]/div/div/span'))
        time.sleep(5)
        self.input(locator=(By.XPATH,'//*[@id="noteContainer"]/div[4]/div[3]/div/div/div[1]/div[1]/div/div/span'),text = '3333')
        time.sleep(5)
        self.click(locator=(By.XPATH,'//*[@id="noteContainer"]/div[4]/div[3]/div/div/div[2]/div/div[2]/button[1]'))
        time.sleep(3)
